<%@ page import="java.util.List" %>
<%@ page import="cap.dao.ChatDao" %>
<%@ page import="cap.dao.impl.ChatDaoImpl" %>
<%@ page import="cap.bean.ChatVo" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <title>聊天室内</title>
    <link rel="stylesheet" type="text/css" href="css/footer.css">
</head>
<body background="picture/logind.jpg" style="background-size: cover;background-attachment: fixed;background-color: white">
<div id="path" style="display: none"><%=basePath%></div>
    <h1 align="center">聊天室</h1>
    <p id="room"></p>
    <button onclick="refresh()">刷新</button>
    <div style="width:80%;height:60% ">
        <table>
            <%
                ChatDao chatDao = new ChatDaoImpl();
                List<ChatVo> chatVos = null;
                try {
                    chatVos = chatDao.reading((String) session.getAttribute("room"));
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
                for(int i=0;i<chatVos.size();i++){
                    %>
            <tr>
                <td><%=chatVos.get(i).getSpeaker()+":"%></td>
                <td><%=chatVos.get(i).getSpeaking()%></td>
            </tr>
            <%
                }
            %>
        </table>
    </div>
    <div>
        <form action="<%=path%>/speaking" method="post">
            <input type="hidden" name="room">
            <input type="text" name="speaking" style="height: 10%;width: 80%">
            <input type="submit"style="height: 10%;width: 10%" value="发送">
            <input type="button" style="height: 10%;width: 5%" value="退出" onclick="exit()">
        </form>
    </div>

</body>
<script>
    document.getElementsByName("room").value=sessionStorage.getItem("room");
    document.cookie = "room=" + sessionStorage.getItem("room");
    function exit() {
        var path=document.getElementById("path").innerText;
        window.location.href =path+"/exit";
    }
    function refresh() {
        var path=document.getElementById("path").innerText;
        window.location.href=path+"front/chatting.jsp";
    }
</script>
</html>
